﻿@model ZSZ.DTO.PermissionDTO[]

@{
    ViewBag.Title = "新增角色";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<form id="formAdd">
    <input type="hidden" name="age" value="3"/>
    <div class="row cl">
        <label class="form-label col-3"><span class="c-red">*</span>管理员：</label>
        <div class="formControls col-5">
            <input type="text" class="input-text" name="name" id="name" datatype="*1-50" nullmsg="角色名称不能为空" />
        </div>
        <div class="col-4"> </div>
    </div>
    <div class="row cl">
        @foreach (var perm in Model)
        {
            <div class="col-xs-12 col-sm-3">
                <input type="checkbox" id="PermissionIds_@perm.Id" name="PermissionIds" value="@perm.Id" />
                <label for="PermissionIds_@perm.Id">@perm.Description</label>
            </div>
        }
    </div>
        <input type="button" value="保存" id="btnSave" />
</form>

@section FooterScript
{
    <script type="text/javascript">
        var saveAjax = function () {
            var formData = $("#formAdd").serializeArray();
            console.log(formData);
            $.ajax({
                url: "/Role/Add",
                type: "post",
                data:formData,
                dataType: "json",
                success: function (res) {
                    if(res.status=="ok")
                    {
                        parent.location.reload();//刷新父窗口
                    }
                    else
                    {
                        alert("error");
                    }
                },
                error: function () { alert("请求出错"); }
            });
        };
        $(function () {
            var validForm = $("#formAdd").Validform({tiptype:2});
            $("#btnSave").click(function () {
                if (validForm.check(false))
                {
                    saveAjax();
                }                
            });
            
        });
    </script>
}